<?php
require_once('config.inc.php');
require_once('DatabaseManager.php');

$db = new DatabaseManager;
$db -> createDB();

PRINT "<html>";
PRINT "<head>";
PRINT	"<title>Benutzer-Daten bearbeiten</title>";
PRINT "<style type=\"text/css\">@import \"template-dragon_form-style.css\";</style>";
PRINT	"</head>";

PRINT "<body>";

$dbname = DB_NAME;

/* make connection to database */
MYSQL_CONNECT(DB_SERVER,DB_USER_NAME,DB_USER_PASSWORD) OR DIE("Datenbankverbindung konnte nicht hergestellt werden!");
@mysql_select_db("$dbname") or die("Datenbank nicht gefunden!"); 

class ChangeUserData
{
	function searchUser()
	{
		/* Get information from table */
		$tablename = "userdata";
		$current_user = $_SESSION['user_id'];
		
		$query = "SELECT * FROM $tablename WHERE user_id = $current_user";
		$result = MYSQL_QUERY($query);
	  $num_rows =  mysql_num_rows($result);
		
		if($num_rows)
		{
		  PRINT "<form id=\"form1\" method=\"post\" action=\"EditUserData.php?user_id=". mysql_result($result, 0, "user_id") ."\">"; 
      PRINT "<div class=\"form-row\"><span class=\"label\">Titel</span><input type=\"text\" name=\"title\" value=\"". mysql_result($result, 0, "title") ."\"/></div>"; 
      PRINT "<div class=\"form-row\"><span class=\"label\">Vorname</span><input type=\"text\" name=\"firstname\" value=\"". mysql_result($result, 0, "firstname") ."\"/></div>"; 
      PRINT "<div class=\"form-row\"><span class=\"label\">Nachname</span><input type=\"text\" name=\"lastname\" value=\"". mysql_result($result, 0, "lastname") ."\"/></div>"; 
      PRINT "<div class=\"form-row\"><span class=\"label\">Adresse</span><input type=\"text\" name=\"address\"  value=\"". mysql_result($result, 0, "address") ."\"/></div>"; 
      PRINT "<div class=\"form-row\"><span class=\"label\">PLZ</span><input type=\"text\" name=\"postcode\"  value=\"". mysql_result($result, 0, "postcode") ."\"/></div>"; 
      PRINT "<div class=\"form-row\"><span class=\"label\">Ort</span><input type=\"text\" name=\"city\"  value=\"". mysql_result($result, 0, "city") ."\"/></div>";
      PRINT "<div class=\"form-row\"><span class=\"label\">Land</span><input type=\"text\" name=\"country\"  value=\"". mysql_result($result, 0, "country") ."\"/></div>";
      PRINT "<div class=\"form-row\"><span class=\"label\">Telefon</span><input type=\"text\" name=\"phone\" value=\"". mysql_result($result, 0, "phone") ."\"/></div>";
      PRINT "<div class=\"form-row\"><span class=\"label\">E-Mail</span><input type=\"text\" name=\"mail\"  value=\"". mysql_result($result, 0, "mail") ."\"/></div>";
      PRINT "<div class=\"form-row\"><span class=\"label\">Homepage</span><input type=\"text\" name=\"homepage\" value=\"". mysql_result($result, 0, "homepage") ."\"/></div>";
      PRINT "<div class=\"form-row\"><span class=\"label\">Arbeitgeber</span><input type=\"text\" name=\"employer\" value=\"". mysql_result($result, 0, "employer") ."\"/></div>"; 
      PRINT "<div class=\"form-row\"><span class=\"label\">Position</span><input type=\"text\" name=\"position\"  value=\"". mysql_result($result, 0, "position") ."\"/></div>"; 
      PRINT "<div class=\"form-row\"><input class=\"submit\" type=\"submit\" value=\"Speichern\"></div>"; 
      PRINT "</form>"; 
      
      PRINT "<form id=\"form2\" method=\"post\" action=\"DeleteUser.php?user_id=". mysql_result($result, 0, "user_id") ."\">";
			PRINT "<div class=\"form-row\"><input class=\"submit\" type=\"submit\" value=\"L&ouml;schen\"></div></form>";
			
			return true;
		}
		else
		{
			PRINT "<strong>Datenbankeintrag nicht gefunden!!!</strong>";
		}
	}
}

//call the changeUserFunktion
$userquery = new ChangeUserData();
$userquery->searchUser();

PRINT "<br>";
PRINT "<a href=\"index.php\">Zur&uuml;ck</a>";
PRINT "</body>";
PRINT "</html>";

/* Close the database connection */
MYSQL_CLOSE();
?>
